﻿using System.Windows;
using Kiva7.Controls;
using Kiva7.DataRequests;
using Kiva7.Baskets;

namespace Kiva7.Pages
{
    public partial class SearchLoanImageControl : BaseUserControl
    {
        public SearchLoanImageControl()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            LoanDetailRequest loan = DataContext as LoanDetailRequest;

            if (loan != null
                && loan.SingleData != null
                && loan.SingleData.Image != null)
            {
                DoNavigate(FullImagePage.GetPageUrl(loan.SingleData.Image.Id));
            }

            //WebBrowserTask task = new WebBrowserTask();
            //task.URL = string.Format("http://www.kiva.org/lend/{0}?app_id={1}", LoanID.Text, "com.codeplex.kiva7");
            //task.Show();        
        }

        private void AddLoan_Click(object sender, RoutedEventArgs e)
        {
            LoanDetailRequest loan = DataContext as LoanDetailRequest;

            if (loan != null
                && loan.SingleData != null
                && loan.SingleData.Image != null)
            {
                Basket.Current.AddItem(loan.SingleData.Id);
                loan.SingleData.IsSelected = true;
            }
        }

        public void TranslateTextWithDetect()
        {
            useTranslation.TranslateTextWithDetect();
        }

    }
}
